﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
[assembly: log4net.Config.XmlConfigurator(Watch = true, ConfigFile = "log4net.config")]
namespace znsd.Utility { 
        //如果是winform或console等c/s程序，需要设置一下。
        //具体步骤：右键log4net.config文件-属性-复制到输出目录：始终复制。目的是为了每次启动时能够找到这个config文件
        /// <summary>
        /// 日志记录类
        /// </summary>
        public class Logger
        {
            #region 记录日志
            /// <summary>
            /// 记录日志
            /// </summary>
            /// <param name="legLevel">日志级别</param>
            /// <param name="msg">日志内容</param>
            public static void LoggerMsg(LogLevel legLevel, string msg)
            {
                log4net.ILog log = GetLogger();
                switch (legLevel)
                {
                    case LogLevel.Debug: log.Debug(msg); break;//Debug
                    case LogLevel.Error: log.Error(msg); break;//Error
                    case LogLevel.Fatal: log.Fatal(msg); break;//Fatal
                    case LogLevel.Info: log.Info(msg); break;//Info
                    case LogLevel.Warn: log.Warn(msg); break;//Warn
                    default: break;
                }
            }
            #endregion

            #region 获得一个日志记录对象
            /// <summary>
            /// 获得一个日志记录对象
            /// </summary>
            /// <returns>日志记录对象</returns>
            public static log4net.ILog GetLogger()
            {
                //MethodBase.GetCurrentMethod().DeclaringType 返回：命名空间名+类名
                return log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            }
            #endregion
        }

        /// <summary>
        /// 日志记录级别
        /// </summary>
        public enum LogLevel
        {
            Debug,
            Info,
            Warn,
            Error,
            Fatal,
        }
    }


